package org.javaymw.springboot.shiro;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;
import org.javaymw.springboot.dto.UserDto;
import org.javaymw.springboot.entity.UserEntity;

/**
 * 加密类
 */
public class PasswordHelper {

	private String algorithmName = "md5";
	private int hashIterations = 2;

	public void encryptPassword(UserDto userDto) {
		String newPassword = new SimpleHash(algorithmName, userDto.getPassWord(),  ByteSource.Util.bytes(userDto.getUserName()), hashIterations).toHex();
		userDto.setPassWord(newPassword);
	}

	public void encryptPassword(UserEntity userEntity) {
		String newPassword = new SimpleHash(algorithmName, userEntity.getPassWord(),  ByteSource.Util.bytes(userEntity.getUserName()), hashIterations).toHex();
		userEntity.setPassWord(newPassword);
	}
}
